import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
//引入element-ui
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import axios from "axios";
import Vant from 'vant';//引入Vant框架
import 'vant/lib/index.css';//引入Vant样式
import BreadCrumb from './components/BreadCrumb'
import * as filters from "./filters/index"
// 导入富文本编辑器
import VueQuillEditor from 'vue-quill-editor'
// 导入富文本编辑器样式
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
// 导入表格树
import TreeTable from 'vue-table-with-tree-grid'


Vue.component(BreadCrumb.name, BreadCrumb)
Vue.config.productionTip = false
Vue.use(ElementUI);
Vue.use(Vant);//配置Vant
Vue.prototype.$axios = axios
// 全局注册富文本编辑器
Vue.use(VueQuillEditor)
// 组件全局注册 表格树
Vue.component('tree-table', TreeTable)

//全局路由拦截
router.beforeEach((to, from, next) => {
  // console.log("from:", from);
  // console.log("to:", to);
  // console.log("to.fullPath", to.fullPath);
  if (to.meta.auth) {
    const token = localStorage.getItem('token')
    if (!token) {
      next({
        name: 'login',
        query: { redirect: to.fullPath }
      })
    } else {
      next()
    }
  } else {
    next();
  }

});

//全局过滤器封装引入
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
